<%--
  Created by IntelliJ IDEA.
  User: Cc
  Date: 2020/12/30
  Time: 16:51
  To change this template use File | Settings | File Templates.
--%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" +
            request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>添加</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="shortcut icon" href="<%=basePath%>static/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="<%=basePath%>static/css/font.css">
    <link rel="stylesheet" href="<%=basePath%>static/css/xadmin.css">
    <script type="text/javascript" src="<%=basePath%>static/js/jquery-3.3.1.min.js"></script>
    <script type="text/javascript" src="<%=basePath%>static/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="<%=basePath%>static/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div class="x-body">
    <form class="layui-form" id="updata_form">
        <div class="layui-form-item">
            <label for="userAccount" class="layui-form-label">
                <span class="x-red">*</span>账号
            </label>
            <div class="layui-input-inline">
                <input type="text" id="userAccount" name="userAccount" required="" lay-verify="userAccount"
                       autocomplete="off" class="layui-input" readonly>
            </div>
        </div>

        <div class="layui-form-item">
            <label for="userPassword" class="layui-form-label">
                密码
            </label>
            <div class="layui-input-inline">
                <input type="text" id="userPassword" name="userPassword" required="" lay-verify="userPassword"
                       autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label for="userName" class="layui-form-label">
                姓名
            </label>
            <div class="layui-input-inline">
                <input type="text" id="userName" name="userName" required="" lay-verify="userPassword"
                       autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label for="userPhone" class="layui-form-label">
                手机
            </label>
            <div class="layui-input-inline">
                <input type="number" id="userPhone" name="userPhone" required="" lay-verify="userPhone"
                       autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label for="userHobby" class="layui-form-label">
                爱好
            </label>
            <div class="layui-input-inline">
                <input type="text" id="userHobby" name="userHobby" required="" lay-verify="userPhone"
                       autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label for="L_repass" class="layui-form-label">
            </label>
            <button class="layui-btn" id="L_repass" type="button">
                修改
            </button>
        </div>
    </form>
</div>

<script>
    $(document).ready(function () {
        //获取localStorage值
        var userAccount = localStorage.getItem("userAccount");
        var userName = localStorage.getItem("userName");
        var userPassword = localStorage.getItem("userPassword");
        var userPhone = localStorage.getItem("userPhone");
        var userHobby = localStorage.getItem("userHobby");
        //给input填充值
        $("#userAccount").val(userAccount);
        $("#userName").val(userName);
        $("#userPassword").val(userPassword);
        $("#userPhone").val(userPhone);
        $("#userHobby").val(userHobby);
    })
    $("#L_repass").click(function () {
        $.ajax({
            url:"<%=basePath%>user/updataUserByUserAccount",
            type:"post",
            dataType:"json",
            data:{"userAccount":$("#userAccount").val(),
                  "userName":$("#userName").val(),
                  "userPassword":$("#userPassword").val(),
                  "userPhone":$("#userPhone").val(),
                  "userHobby":$("#userHobby").val(),
            },
            success:function (data) {
                if (data==="success"){
                    layer.alert("修改成功",{icon:1},function () {
                        //获取当前frame
                        var index=parent.layer.getFrameIndex(window.name);
                        //关闭
                        parent.layer.close(index);
                        //刷新
                        parent.location.reload();
                    });
                }else{
                    layer.alert("修改失败",{icon:2},function () {
                        //获取当前frame
                        var index=parent.layer.getFrameIndex(window.name);
                        //关闭子页面
                        parent.layer.close(index);
                        //刷新父页面
                        parent.location.reload();
                    });
                }
            },error:function () {
                alert("服务器错误");
            }
        })
    })
</script>
</body>
</html>